cmake_minimum_required(VERSION 3.5)
project(myAPP)
set(CMAKE_BUILD_TYPE Release)

set(RK_SDK_PATH "/home/flamebox/rv1106/rv1106_sdk_ubuntu_lvgl_buildroot")
set(RK_APP_OUTPUT ${RK_SDK_PATH}/output/out/app_out)
set(RK_APP_MEDIA_LIBS_PATH ${RK_SDK_PATH}/output/out/media_out/lib)
set(RK_APP_MEDIA_INCLUDE_PATH ${RK_SDK_PATH}/output/out/media_out/include)

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_FLAGS -Wl,-rpath-link,${RK_APP_MEDIA_LIBS_PATH}:${RK_APP_OUTPUT}/lib)
set(CMAKE_CXX_FLAGS -Wl,-rpath-link,${RK_APP_MEDIA_LIBS_PATH}:${RK_APP_OUTPUT}/lib)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdata-sections -ffunction-sections -Wl,-rpath-link,${CMAKE_CURRENT_SOURCE_DIR}/lib/arm-rockchip830-linux-gnueabihf")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections -ffunction-sections -Wl,-rpath-link,${CMAKE_CURRENT_SOURCE_DIR}/lib/arm-rockchip830-linux-gnueabihf")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -Wl,--as-needed")
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")

include_directories(${RK_APP_MEDIA_INCLUDE_PATH}
					${RK_APP_MEDIA_INCLUDE_PATH}/libdrm
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq/uAPI
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq/uAPI2
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq/algos
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq/common
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq/xcore
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq/iq_parser
					${RK_APP_MEDIA_INCLUDE_PATH}/rkaiq/iq_parser_v2
					${RK_APP_MEDIA_INCLUDE_PATH}/rga
					${RK_APP_OUTPUT}/include
					${RK_APP_OUTPUT}/include/freetype2
					${RK_APP_MEDIA_INCLUDE_PATH}/easymedia
)

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/audio SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/video SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/isp/rv1106 SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/ SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/socket_server SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/param SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/system SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/rtsp SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/rtmp SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/osd SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/roi SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/network SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/storage SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/rockiva SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/event SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/common/region_clip SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/yolo/src SRCS)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/audio
					${CMAKE_CURRENT_SOURCE_DIR}/common/isp/rv1106
					${CMAKE_CURRENT_SOURCE_DIR}/src/video
					${CMAKE_CURRENT_SOURCE_DIR}/common
					${CMAKE_CURRENT_SOURCE_DIR}/common/socket_server
					${CMAKE_CURRENT_SOURCE_DIR}/common/rtsp
					${CMAKE_CURRENT_SOURCE_DIR}/common/rtmp
					${CMAKE_CURRENT_SOURCE_DIR}/common/param
					${CMAKE_CURRENT_SOURCE_DIR}/common/system
					${CMAKE_CURRENT_SOURCE_DIR}/common/osd
					${CMAKE_CURRENT_SOURCE_DIR}/common/osd/freetype2
					${CMAKE_CURRENT_SOURCE_DIR}/common/roi
					${CMAKE_CURRENT_SOURCE_DIR}/common/network
					${CMAKE_CURRENT_SOURCE_DIR}/common/storage
					${CMAKE_CURRENT_SOURCE_DIR}/common/rockiva
					${CMAKE_CURRENT_SOURCE_DIR}/common/event
					${CMAKE_CURRENT_SOURCE_DIR}/common/region_clip
					${CMAKE_CURRENT_SOURCE_DIR}/src/yolo/include
					)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib/arm-rockchip830-linux-uclibcgnueabihf
				 ${RK_APP_MEDIA_LIBS_PATH}
				 ${RK_APP_OUTPUT}/lib
				)

# RKNN 相关
add_definitions(-DPLATFORM_RV1106_1103)
add_definitions(-DRV110X_DEMO)
add_definitions(-DRKDMO_NPU_2_NATIVE_ZP)

# lvgl
include_directories(lvgl_app)
add_subdirectory(lvgl_app)

#onenet
include_directories(mqtts_onejson)
add_subdirectory(mqtts_onejson)

# 主程序
add_executable(${PROJECT_NAME} ${SRCS})
target_link_libraries(${PROJECT_NAME} pthread rockit rockchip_mpp rkaiq rtsp
									  rkaudio_detect aec_bf_process rockiva freetype
									  wpa_client m rkmuxer iconv rknnmrt rga stdc++
									  rksysutils lvgl_app mqtts_onejson)

# RKNN DEMO
# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/yolo RKNN_DEMO_SRC)
# aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/yolo/src RKNN_DEMO_SRC)
# add_executable(rknn_demo ${RKNN_DEMO_SRC})
# target_link_libraries(rknn_demo pthread rknnmrt rga)

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES rkipc-300w.ini DESTINATION share)
install(FILES rkipc-400w.ini DESTINATION share)
install(FILES rkipc-500w.ini DESTINATION share)
install(FILES ../../common/speaker_test.wav DESTINATION share)
install(PROGRAMS RkLunch.sh DESTINATION bin)
install(PROGRAMS RkLunch-stop.sh DESTINATION bin)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/common/osd/image.bmp DESTINATION share)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/common/osd/simsun_en.ttf DESTINATION share)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lib/arm-rockchip830-linux-uclibcgnueabihf/libwpa_client.so DESTINATION lib)
